using System;
using System.Globalization;
using NUnit.Framework;

namespace PaulRz.Util
{
	/// <summary>
	/// Summary description for FormatProvider.
	/// </summary>
	

		public class FormatProvider : IFormatProvider
		{
			private DateTimeFormatInfo formatInfo;
			private FormatProvider(String dataFormat)
			{
				formatInfo= new CultureInfo("cs-CZ").DateTimeFormat;
				formatInfo.ShortDatePattern=dataFormat;
			}
			private static IFormatProvider CRM_FORMAT;
			private static IFormatProvider IVR_FORMAT;
			public static IFormatProvider CRM
			{
				get 
				{
					if(CRM_FORMAT==null)
					{
						CRM_FORMAT=new FormatProvider("dd.MM.yyyy");
					}
					return CRM_FORMAT;
				}
			}

			public static IFormatProvider IVR
			{
				get 
				{
					if(IVR_FORMAT==null)
					{
						IVR_FORMAT=new FormatProvider("dd.MM.yyyy");
					}
					return IVR_FORMAT;
				}
			}

			private static IFormatProvider SMS_FORMAT;
			public static IFormatProvider SMS
			{
				get
				{
					if (SMS_FORMAT == null)
					{
						SMS_FORMAT = new FormatProvider("yyMMddHHmmss0");
					}
					return SMS_FORMAT;
				}
			}

			public object GetFormat(Type formatType)
			{
				return formatInfo;
			}

		
		}

	
	public class TestProvider
	{
		[Test]
		public void test()
		{
			Assert.AreEqual("27.11.2005 14:30:54", DateTime.Parse("27.11.2005 14:30:54.333",FormatProvider.CRM).ToString());
			Assert.AreEqual("27.11.2005", DateTime.Parse("27.11.2005 14:30:54.333",FormatProvider.IVR).ToString("d"));
			Assert.AreEqual("27.11.2005 14:30:54", DateTime.Parse("27.11.2005 14:30:54.333",FormatProvider.IVR).ToString());
		}

        [Test]
        public void smsTest()
        {
            string testTimeAm = "27.11.2006 4:03:23";
            string testTimePm = "27.11.2006 16:03:23";

            DateTime dtAm = DateTime.Parse(testTimeAm, FormatProvider.CRM);
            DateTime dtPm = DateTime.Parse(testTimePm, FormatProvider.CRM);

            Console.WriteLine(dtAm.ToString("d", FormatProvider.SMS));
            Console.WriteLine(dtPm.ToString("d", FormatProvider.SMS));
        }
	}
	
}
